package com.xm.clj.underserver.controller;

import com.alibaba.fastjson.JSON;
import com.xm.clj.underserver.bean.RegUser;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class DoTest {

    RestTemplate restTemplate = new RestTemplate();

    @RequestMapping("/doTest")
    public String test(){
        return "hello";
    }

    @RequestMapping("/doReg")
    public String testReg(){
        RegUser regUser = new RegUser();
        regUser.setAccount_id("121");
        regUser.setUsername("clj");
        regUser.setPassword("123");
        regUser.setRepassword("123");
        String json = JSON.toJSONString(regUser);
        String url = "http://192.168.10.11:8080/reg";
        HttpHeaders headers = new HttpHeaders();
        MediaType mediaType = MediaType.parseMediaType("application/json;charset=UTF-8");
        headers.setContentType(mediaType);
        headers.add("Accept",MediaType.APPLICATION_JSON.toString());
        HttpEntity<String> formEntity = new HttpEntity<String>(json,headers);
        String s = restTemplate.postForEntity(url,formEntity,String.class).getBody();
        return s;
    }
}
